package com.flot.yazb.home.setting;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flot.yazb.R;
import com.flot.yazb.base.BActivity;
import com.flot.yazb.base.BApplication;
import com.flot.yazb.base.model.BModel;
import com.flot.yazb.aop.stub.CodeStub;
import com.flot.yazb.model.user.SelfDetailModel;
import com.flot.yazb.model.user.SelfModel;
import com.flot.yazb.model.user.UserModel;
import com.flot.yazb.widget.utils.GlideImageLoaderUtil;
import com.flot.yazb.widget.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;



public class SelfMessageActivity extends BActivity {
    @BindView(R.id.icon)
    ImageView icon;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.beizhu)
    TextView beizhu;
    @BindView(R.id.tltit)
    RelativeLayout tltit;
    @BindView(R.id.tvGradu)
    TextView tvGradu;
    @BindView(R.id.tvMoney)
    TextView tvMoney;
    @BindView(R.id.tvWork)
    TextView tvWork;
    @BindView(R.id.tvWeight)
    TextView tvWeight;
    @BindView(R.id.tvHeight)
    TextView tvHeight;
    @BindView(R.id.tvXuexing)
    TextView tvXuexing;
    @BindView(R.id.tvXHunyin)
    TextView tvXHunyin;
    @BindView(R.id.tvRoom)
    TextView tvRoom;
    @BindView(R.id.tvChild)
    TextView tvChild;
    @BindView(R.id.tvyidi)
    TextView tvyidi;
    @BindView(R.id.tvyiditype)
    TextView tvyiditype;
    @BindView(R.id.tvSexlove)
    TextView tvSexlove;
    @BindView(R.id.tvTogetherwithmm)
    TextView tvTogetherwithmm;
    @BindView(R.id.tvmeili)
    TextView tvmeili;
    private UserModel model = BApplication.getInstance().getUserModel();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myself_msg);
        ButterKnife.bind(this);
        getData();
        initView();
    }

    private void getData() {
        SelfModel.getUserMsg(model.id, new BModel.Transit<SelfModel>(this) {
            @Override
            public void onBorn(SelfModel serializable, String code, String message) {
                if (code.equals(CodeStub.B_OK)) {
                    if (serializable == null)
                        return;
                    tvGradu.setText(serializable.education);
                    tvMoney.setText(serializable.income);
                    tvWork.setText(serializable.job);
                    tvWeight.setText(serializable.weight);
                    tvHeight.setText(serializable.height);
                    tvXuexing.setText(serializable.blood);
                    tvXHunyin.setText(serializable.marriage);
                    tvRoom.setText(serializable.house);
                } else {
                    ToastUtil.showToast(activity, message);
                }

            }
        });

        SelfDetailModel.getUserMsg(model.id, new BModel.Transit<SelfDetailModel>(this) {
            @Override
            public void onBorn(SelfDetailModel serializable, String code, String message) {
                if (code.equals(CodeStub.B_OK)) {
                    if (serializable == null)
                        return;
                    tvChild.setText(serializable.child);
                    tvyidi.setText(serializable.yidi);
                    tvyiditype.setText(serializable.leixin);
                    tvSexlove.setText(serializable.sex);
                    tvTogetherwithmm.setText(serializable.fumu);
                    tvmeili.setText(serializable.meili);
                } else {
                    ToastUtil.showToast(activity, message);
                }
            }
        });
    }

    private void initView() {
        GlideImageLoaderUtil.loadImage(icon, model.avatar, R.mipmap.activity_splash_background);
        name.setText(model.nicheng);
        address.setText(model.province + "  " + model.city);
        if ((null != model.beizhu) && (!"".equals(model.beizhu)))
            beizhu.setText(model.beizhu);

    }

    @OnClick(R.id.iv_back)
    public void onClick() {
    }
}
